import { BASE_URL } from '@/config';
import { request } from '@/utils/request';
import type { UserInfo, UserStats } from '@/types/user';

/**
 * 用户相关接口
 * 职责：用户信息、统计数据的查询和更新
 */

// 获取用户个人信息
export function getUserProfile(customerId: number) {
  return request<UserInfo>({
    url: `${BASE_URL}/user/users/profile/${customerId}`,
    method: 'GET'
  });
}

// 更新用户个人信息
export function updateUserProfile(customerId: number, data: Partial<UserInfo>) {
  return request({
    url: `${BASE_URL}/user/users/profile/${customerId}`,
    method: 'PUT',
    data
  });
}

// ⭐ 获取用户统计数据（新增）
export function getUserStats(customerId: number) {
  return request<UserStats>({
    url: `${BASE_URL}/user/users/${customerId}/stats`,
    method: 'GET'
  });
}

// 上传头像
export function uploadAvatar(customerId: number, filePath: string) {
  return uni.uploadFile({
    url: `${BASE_URL}/user/users/${customerId}/avatar`,
    filePath: filePath,
    name: 'file',
    header: {
      'Authorization': uni.getStorageSync('token')
    }
  });
}